package com.one.apartmentsystem.app.controller;

import com.one.apartmentsystem.app.dto.PageDTO;
import com.one.apartmentsystem.app.service.HousesInfoService;
import com.one.apartmentsystem.app.vo.HouseDetailsVO;
import com.one.apartmentsystem.app.vo.PageResultVO;
import com.one.apartmentsystem.common.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 房屋信息接口
 * @author mpk
 * @since 2024/8/3 13:48:42
 */
@RestController
@CrossOrigin
@RequestMapping("/app/house")
public class HouseController {

    /**
     * 房屋信息服务，用于获取房屋信息
     */
     @Resource
    HousesInfoService housesInfoService;

    /**
     * 分页获取房屋信息
     *
     * @param pageDTO 分页参数，包含页码和每页数量等信息
     * @return 房屋分页信息
     */
    @PostMapping("/page")
    public Result page (@RequestBody PageDTO pageDTO){

        PageResultVO<HouseDetailsVO> housePageVO= housesInfoService.pageList(pageDTO);

        return Result.ok(housePageVO);
    }

    /**
     * 根据合同ID获取房屋详细信息
     *
     * @param contractId 合同id对应的房屋
     * @return 房屋详细信息
     */
    @GetMapping("/{contractId}")
    public Result getHouse(@PathVariable String contractId){


        HouseDetailsVO houseDetailsVO= housesInfoService.getHouseDetail(contractId);

        return Result.ok(houseDetailsVO);
    }

    /**
     * 用户id查询已签约
     * @param userId 用户id
     * @return HouseDetailsVO
     */
    @GetMapping("/user/{userId}")
    public Result getHouseByUserId(@PathVariable Long userId){


        List<HouseDetailsVO> houseDetailsVO= housesInfoService.getHouseByUserId(userId);

        return Result.ok(houseDetailsVO);
    }

}

